<?php
namespace app\wx\model;
use think\Db;
use think\Model;

class Order extends Model
{
    protected $table = 'cbdd_park_order';


    public function addParkOrder($param){
        $result = $this->allowField(true)->save($param);
        return $result;
    }
    // 查看订单详情
    public function getParkOrderDetail($param)
    {
        $data = $this->where('id',$param['orderId'])->where('uid',$param['uid'])->find();
        return $data;
    }

    public function getParkOrderList($param)
    {
        $data = $this->alias('a')->where('uid',$param['uid'])->join('cbdd_park b','a.park_id = b.id')->select();
        foreach ($data as $key => &$v) {
            $v['show_time'] = date('Y-m-d H:i:s',($v['order_time'] + $v['day'] *60*60*24));
            $v['order_time'] = date('Y-m-d H:i:s',$v['order_time']);
        }
        unset($key);
        unset($v);
        return $data;
    }

    //获取首页订单
    public function getCommonOrderList($page,$orll_page,$param){
        $i = config('distance'); //差值可自定义，值越大，范围就越大
        $min_latitude = $param['lat'] - $i; //纬度最小值
        $max_latitude = $param['lat'] + $i; //纬度最大值
        $min_longitude = $param['lng'] - $i; //经度最小值
        $max_longitude = $param['lng'] + $i; //经度最大值
        if($param['type']){
            $where['type'] = $param['type'];
        }else{
            $where['type'] = ['lt',3];
        }      
        $time_type = [1=>1, 2=>2, 3=>4, 4=>6, 5=>8];
        if(array_key_exists($param['time_type'],$time_type)){
            $where['time']= ['>',time()-$time_type[$param['time_type']]*60*60];
        }
        $field = ['a.id', 'tip','start_name','uid','content', 'category_name','type','b.name','service_type','base_price','tip','time','start_lat', 'start_lng','start_province','a.start_city', 'a.start_dist', 'start_detail','start_citycode', 'start_adcode','b.name bname', 'a.end_lat', 'a.end_lng', 'a.end_name', 'a.end_mobile', 'a.end_province', 'a.end_city', 'a.end_dist', 'a.end_detail','a.status','is_new_order','orders_type','buy_type','a.cid','mileage'];
        $order_list['row'] = Db::table('slzd_order_rrb a')
            ->join('slzd_rrb_list b','b.id = a.type')
            ->page($page,$orll_page)
            ->where($where)
            ->where('end_lat','between',[$min_latitude,$max_latitude])
            ->where('end_lng','between',[$min_longitude,$max_longitude])
            ->where('(a.status = 1 and is_new_order < 1 ) or (a.status = 3 and is_new_order = 1 )')
            ->where('orders_type',0)
            ->field($field)
            ->order('a.id desc')
            ->select();
        $total = Db::table('slzd_order_rrb a')
            ->join('slzd_rrb_list b','b.id = a.type')
            ->page($page,$orll_page)
            ->where($where)
            ->where('(a.status = 1 and is_new_order < 1 ) or (a.status = 3 and is_new_order = 1 )')
            ->where('orders_type',0)
            ->where('end_lat','between',[$min_latitude,$max_latitude])
            ->where('end_lng','between',[$min_longitude,$max_longitude])
            ->count();
        $order_list['count'] = ceil($total/$orll_page);
        $order_list['page'] = $page;
        $order_list['rrbAuth'] = (string)Db::table('slzd_driver')
            ->where('driverId',$param['id'])
            ->value('rrbAuth');
        foreach($order_list['row'] as $key => &$value){
            $value['start_address'] = $value['start_province']. $value['start_city'] .$value['start_dist'].$value['start_detail'];
            $value['end_address'] = $value['end_province']. $value['end_city'] .$value['end_dist'].$value['end_detail'];
            if($value['start_lat'] == 0.00000 && $value['start_lng'] == 0.00000){
                $value['start_kilometers'] =  getDistanceBetweenPointsNew($param['lat'],$param['lng'],$value['start_lat'],$value['start_lng']);
                $value['show_start_kilometers'] ='';
                $value['start_kilometers'] =  $value['start_kilometers']['kilometers'];
            }else{
                $value['start_kilometers'] =  getDistanceBetweenPointsNew($param['lat'],$param['lng'],$value['start_lat'],$value['start_lng']);
                if(is_float($value['start_kilometers']['kilometers'])){
                    $len = strpos($value['start_kilometers']['kilometers'],'.');
                    $value['show_start_kilometers'] =substr($value['start_kilometers']['kilometers'],0,($len+2)).'公里';
                }else{
                    $value['show_start_kilometers'] = $value['start_kilometers']['kilometers'].'公里';
                }
                $value['start_kilometers'] =  $value['start_kilometers']['kilometers'];
            }
            $value['end_kilometers'] =  getDistanceBetweenPointsNew($param['lat'],$param['lng'],$value['end_lat'],$value['end_lng']);
            if(is_float($value['end_kilometers']['kilometers'])){
                $len = strpos($value['end_kilometers']['kilometers'],'.');
                $value['show_end_kilometers'] =substr($value['end_kilometers']['kilometers'],0,($len+2)).'公里';
            }else{
                $value['show_end_kilometers'] = $value['end_kilometers']['kilometers'].'公里';
            }
            $value['end_kilometers'] =  $value['end_kilometers']['kilometers'];
            if($value['cid'] == 33){
                if($value['type'] == 2){
               $value['all_price'] = ($value['base_price']-$value['tip'])/100*100/100+$value['tip']/100;
                }else{
                    if($value['type'] == 1 && $value['buy_type'] == 3){
                        $value['all_price'] =  ($value['base_price']-$value['tip'])/100*100/100;
                    }else{
                        $value['all_price'] = ($value['base_price']-$value['tip'])/100*100/100+$value['tip']/100;
                    }
                }
            }else{
                if($value['type'] == 2){
               $value['all_price'] = ($value['base_price']-$value['tip'])/100*80/100+$value['tip']/100;
                }else{
                    if($value['type'] == 1 && $value['buy_type'] == 3 ){
                        $value['all_price'] =  ($value['base_price']-$value['tip'])/100*80/100;
                    }else{
                        $value['all_price'] = ($value['base_price']-$value['tip'])/100*80/100+$value['tip']/100;
                    }
                }
            }
            $value['showtime'] = $value['time'] == 0 ? '立即送达' : date('Y-m-d H:i:s',$value['time']);
            switch($value['type']){
                case 1 :
                    $value['showtype'] = '帮买';
                    break;
                case 2 :
                    $value['showtype'] = '帮送';
                    break;
                case 3 :
                    $value['showtype'] = '帮办';
                    break;
            }
            $value['show_mileage'] = $value['mileage'].'公里';
            if($value['is_new_order'] == 1 && $value['status'] == 1){
                array_splice($order_list['row'],$key,1);
                // unset($key);
            }
            if($value['is_new_order'] < 1 && $value['status'] == 3){
                array_splice($order_list['row'],$key,1);
            }
        }
        return $order_list;
    }
    //获取首页订单
    public function getRrbOrderList($page,$orll_page,$param){
        $i = config('distance'); //差值可自定义，值越大，范围就越大
        $min_latitude = $param['lat'] - $i; //纬度最小值
        $max_latitude = $param['lat'] + $i; //纬度最大值
        $min_longitude = $param['lng'] - $i; //经度最小值
        $max_longitude = $param['lng'] + $i; //经度最大值
        $limit = ($page-1)*$orll_page;
        $field = " bwz.id,bwz.created_at created_at,bwz.status,uid,content list,remark content,category_name,4 type,'帮我赚' name, service_type,base_price,'' tip,time,0.00000 start_lat,0.00000 start_lng,
        '' begin,end, '' start_citycode,'' start_adcode,g.name bname,lat end_lat,lng end_lng";
        $field1 = " rrb.id,rrb.created_at created_at,rrb.status,uid,'' list,content,category_name,l.id type,l.name,service_type,base_price,tip,time,start_lat,start_lng,begin,end,
        start_citycode,start_adcode,l.name bname,end_lat,end_lng";
        $sql = "SELECT".$field." FROM slzd_order_bwz as  bwz join slzd_rrb_getlist g on  bwz.type = g.id WHERE bwz.status = 1
                        union all 
                SELECT ".$field1." FROM  slzd_order_rrb as rrb join slzd_rrb_list l on  rrb.type = l.id WHERE  rrb.status = 1
                ORDER BY created_at DESC LIMIT ".$limit.",".$orll_page;
        $list['row'] =  Db::query($sql);
        $sql = "select sum(tmpcount) from (
                        SELECT count(*) as tmpcount FROM  slzd_order_rrb as rrb  WHERE rrb.status =1
                        union all
                        SELECT count(*) as tmpcount FROM slzd_order_bwz as bwz WHERE  bwz.status = 1
                    ) as a";
        $count =  $this->query($sql);
        $list['count'] = ceil(($count[0]['sum(tmpcount)'])/$orll_page);
        $list['page'] =  $page;
//        if($param['time_type']==1 && $param['type']){
//            $where['time'] = ['>',time()-60*60];
//            $where['a.status'] = 1;
//            $where['type'] = $param['type'];
//        }elseif($param['time_type']==2 && $param['type']){
//            $where['time'] = ['>',time()-2*60*60];
//            $where['a.status'] = 1;
//            $where['type'] = $param['type'];
//        }elseif($param['time_type']==3 && $param['type']){
//            $where['time'] = ['>',time()-4*60*60];
//            $where['a.status'] = 1;
//            $where['type'] = $param['type'];
//        }elseif($param['time_type']==4 && $param['type']){
//            $where['time'] = ['>',time()-6*60*60];
//            $where['a.status'] = 1;
//            $where['type'] = $param['type'];
//        }elseif($param['time_type']==5 && $param['type']){
//            $where['time'] = ['>',time()-8*60*60];
//            $where['a.status'] = 1;
//            $where['type'] = $param['type'];
//        }elseif($param['time_type']==1){
//            $where['time'] = ['>',time()-60*60];
//            $where['a.status'] = 1;
//        }elseif($param['time_type']==2){
//            $where['time'] = ['>',time()-2*60*60];
//            $where['a.status'] = 1;
//        }elseif($param['time_type']==3){
//            $where['time'] = ['>',time()-4*60*60];
//            $where['a.status'] = 1;
//        }elseif($param['time_type']==4){
//            $where['time'] = ['>',time()-6*60*60];
//            $where['a.status'] = 1;
//        }elseif($param['time_type']==5){
//            $where['time'] = ['>',time()-8*60*60];
//            $where['a.status'] = 1;
//        }elseif($param['type'] == 1||$param['type'] == 2||$param['type'] == 3) {
//            $where['type'] = $param['type'];
//            $where['a.status'] = 1;
//        }else{
//            $where['a.status'] = 1;
//        }
//        $field = ['a.id', 'start_name','uid','content', 'category_name','type','b.name','service_type','base_price','tip','time','start_lat', 'start_lng','start_province','a.start_city', 'a.start_dist', 'start_detail','start_citycode', 'start_adcode','b.name bname', 'a.end_lat', 'a.end_lng', 'a.end_name', 'a.end_mobile', 'a.end_province', 'a.end_city', 'a.end_dist', 'a.end_detail'];
//        $order_list['row'] = Db::table('slzd_order_rrb a')
//            ->join('slzd_rrb_list b','b.id = a.type')
//            ->page($page,$orll_page)
//            ->where($where)
//            ->where('end_lat','between',[$min_latitude,$max_latitude])
//            ->where('end_lng','between',[$min_longitude,$max_longitude])
//            ->field($field)
//            ->order('a.id desc')
//            ->select();
//        $total = Db::table('slzd_order_rrb a')
//            ->join('slzd_rrb_list b','b.id = a.type')
//            ->page($page,$orll_page)
//            ->where($where)
//            ->where('end_lat','between',[$min_latitude,$max_latitude])
//            ->where('end_lng','between',[$min_longitude,$max_longitude])
//            ->count();
//        $order_list['count'] = ceil($total/$orll_page);
//        $order_list['page'] = $page;
        foreach($list['row'] as $key => &$value){
            if($value['start_lat'] == 0.00000 && $value['start_lng'] == 0.00000){
                $value['start_kilometers'] =  getDistanceBetweenPointsNew($param['lat'],$param['lng'],$value['start_lat'],$value['start_lng']);
                $value['show_start_kilometers'] ='';
                $value['start_kilometers'] =  $value['start_kilometers']['kilometers'];
            }else{
                $value['start_kilometers'] =  getDistanceBetweenPointsNew($param['lat'],$param['lng'],$value['start_lat'],$value['start_lng']);
                if(is_float($value['start_kilometers']['kilometers'])){
                    $len = strpos($value['start_kilometers']['kilometers'],'.');
                    $value['show_start_kilometers'] =substr($value['start_kilometers']['kilometers'],0,($len+2)).'公里';
                }else{
                    $value['show_start_kilometers'] = $value['start_kilometers']['kilometers'].'公里';
                }
                $value['start_kilometers'] =  $value['start_kilometers']['kilometers'];
            }
            $value['end_kilometers'] =  getDistanceBetweenPointsNew($param['lat'],$param['lng'],$value['end_lat'],$value['end_lng']);
            if(is_float($value['end_kilometers']['kilometers'])){
                $len = strpos($value['end_kilometers']['kilometers'],'.');
                $value['show_end_kilometers'] =substr($value['end_kilometers']['kilometers'],0,($len+2)).'公里';
            }else{
                $value['show_end_kilometers'] = $value['end_kilometers']['kilometers'].'公里';
            }
            $value['end_kilometers'] =  $value['end_kilometers']['kilometers'];
            $value['show_price'] =  ($value['base_price'])/100;
            $value['list'] =  unserialize($value['list']);
            $value['showtime'] = $value['time'] == 0 ? '立即送达' : date('Y-m-d H:i:s',$value['time']);

            switch($value['type']){
                case 1 :
                    $value['showtype'] = '帮买';
                    break;
                case 2 :
                    $value['showtype'] = '帮送';
                    break;
                case 3 :
                    $value['showtype'] = '帮办';
                    break;
                case 4 :
                    $value['showtype'] = '帮赚';
                    break;
            }
        }
        return $list;
    }
    public function getDriverAllData($page,$orll_page,$param){
        $limit = ($page-1)*$orll_page;
        if($param['status']==6){
            $sql = "SELECT kd.id id,kd.created_at created_at,kd.updated_at updated_at,kd.status status,time,time0,time2,time3,time5,begin,end,base_price,1 type,ex.name,ex.id ctype FROM slzd_order_kd as kd join slzd_app_express ex on kd.express_type = ex.id WHERE kd.did = ".$param['id']." and kd.del_user = 0 and kd.status IN(0,2,3,4,5,6)
                        union all SELECT id,created_at,updated_at,status,time,time0,time2,time3,time5,begin,end,base_price,4 as type,'顺风车' name,99 ctype FROM slzd_order_ky as  ky WHERE ky.did = ".$param['id']." and ky.del_user = 0 and ky.status IN(0,2,3,4,5,6) 
                        union all SELECT rrb.id id,rrb.created_at created_at,rrb.updated_at updated_at,rrb.status status,time,time0,time2,time3,time5,begin,end,base_price,2 type,l.name name,l.id ctype FROM  slzd_order_rrb as rrb join slzd_rrb_list l on  rrb.type = l.id WHERE rrb.orders_type =1 and rrb.did = ".$param['id']." and rrb.orders_type = 1 and  rrb.del_user = 0 and rrb.status IN(0,2,3,4,5,6) 
                        union all SELECT id,created_at,updated_at,status,time,time0,time2,time3,time5,begin,end,base_price,3 as type,'货急送' name, 0 ctype FROM slzd_order_hy as hy WHERE hy.did = ".$param['id']." and hy.del_user = 0 and hy.status IN(0,2,3,4,5,6) ORDER BY updated_at DESC LIMIT ".$limit.",".$orll_page;
            $list['row'] =  Db::query($sql);
            $sql = "select sum(tmpcount) from (
                        select count(*) as tmpcount from slzd_order_kd kd WHERE kd.did = ".$param['id']." and kd.del_user = 0 and kd.status IN (0,2,3,4,5,6)
                        union all 
                        select count(*) as tmpcount from slzd_order_ky ky WHERE ky.did = ".$param['id']." and ky.del_user = 0 and ky.status IN (0,2,3,4,5,6)
                        union all
                        SELECT count(*) as tmpcount FROM  slzd_order_rrb as rrb  WHERE rrb.did = ".$param['id']." and rrb.del_user = 0 and rrb.orders_type =1 and rrb.status IN (0,2,3,4,5,6)
                        union all
                        SELECT count(*) as tmpcount FROM slzd_order_hy as hy WHERE hy.did = ".$param['id']." and hy.del_user = 0 and hy.status IN (0,2,3,4,5,6)
                    ) as a";
            $count =  $this->query($sql);
            $list['count'] = ceil(($count[0]['sum(tmpcount)'])/$orll_page);
            $list['page'] =  $page;
        }elseif($param['status'] ==2 ){
            $sql = "SELECT kd.id id,kd.created_at created_at,kd.updated_at updated_at,kd.status status,time,time0,time2,time3,time5,begin,end,base_price,1 type,ex.name,ex.id ctype FROM slzd_order_kd as kd join slzd_app_express ex on kd.express_type = ex.id WHERE kd.did = ".$param['id']." and kd.del_user = 0 and kd.status IN(2,6)
                        union all SELECT id,created_at, updated_at,status,time,time0,time2,time3,time5,begin,end,base_price,4 as type,'顺风车' name,99 ctype FROM slzd_order_ky as  ky WHERE ky.did = ".$param['id']." and ky.del_user = 0 and ky.status IN(2,6) 
                        union all SELECT rrb.id id,rrb.created_at created_at,rrb.updated_at updated_at,rrb.status status,time,time0,time2,time3,time5,begin,end,base_price,2 type,l.name name,l.id ctype FROM  slzd_order_rrb as rrb join slzd_rrb_list l on  rrb.type = l.id WHERE rrb.orders_type =1 and rrb.did = ".$param['id']." and rrb.orders_type = 1 and  rrb.del_user = 0 and rrb.status IN(2,6) 
                        union all SELECT id,created_at,updated_at,status,time,time0,time2,time3,time5,begin,end,base_price,3 as type,'货急送' name, 0 ctype FROM slzd_order_hy as hy WHERE hy.did = ".$param['id']." and hy.del_user = 0 and hy.status IN(2,6) ORDER BY updated_at DESC LIMIT ".$limit.",".$orll_page;
            $list['row'] =  Db::query($sql);
            $sql = "select sum(tmpcount) from (
                        select count(*) as tmpcount from slzd_order_kd kd WHERE kd.did = ".$param['id']." and kd.del_user = 0 and kd.status IN (2,6)
                        union all
                        select count(*) as tmpcount from slzd_order_ky ky WHERE ky.did = ".$param['id']." and ky.del_user = 0 and ky.status IN (2,6)
                        union all
                        SELECT count(*) as tmpcount FROM  slzd_order_rrb as rrb  WHERE rrb.did = ".$param['id']." and rrb.del_user = 0 and rrb.orders_type =1 and rrb.status IN (2,6)
                        union all
                        SELECT count(*) as tmpcount FROM slzd_order_hy as hy WHERE hy.did = ".$param['id']." and hy.del_user = 0 and hy.status IN (2,6)
                    ) as a";
            $count =  $this->query($sql);
            $list['count'] = ceil(($count[0]['sum(tmpcount)'])/$orll_page);
            $list['page'] =  $page;
        }elseif($param['status'] ==3 ){
            $sql = "SELECT kd.id id,kd.created_at created_at,kd.updated_at updated_at,kd.status status,time,time0,time2,time3,time5,begin,end,base_price,1 type,ex.name,ex.id ctype FROM slzd_order_kd as kd join slzd_app_express ex on kd.express_type = ex.id WHERE kd.did = ".$param['id']." and kd.del_user = 0 and kd.status IN(3,4)
                        union all SELECT id,created_at, updated_at,status,time,time0,time2,time3,time5,begin,end,base_price,4 as type,'顺风车' name,99 ctype FROM slzd_order_ky as  ky WHERE ky.did = ".$param['id']." and ky.del_user = 0 and ky.status IN(3,4) 
                        union all SELECT rrb.id id,rrb.created_at created_at,rrb.updated_at updated_at,rrb.status status,time,time0,time2,time3,time5,begin,end,base_price,2 type,l.name name,l.id ctype FROM  slzd_order_rrb as rrb join slzd_rrb_list l on  rrb.type = l.id WHERE rrb.orders_type =1 and rrb.did = ".$param['id']." and rrb.orders_type = 1 and  rrb.del_user = 0 and rrb.status IN(3,4) 
                        union all SELECT id,created_at,updated_at,status,time,time0,time2,time3,time5,begin,end,base_price,3 as type,'货急送' name, 0 ctype FROM slzd_order_hy as hy WHERE hy.did = ".$param['id']." and hy.del_user = 0 and hy.status IN(3,4) ORDER BY updated_at DESC LIMIT ".$limit.",".$orll_page;
            $list['row'] =  Db::query($sql);
            $sql = "select sum(tmpcount) from (
                        select count(*) as tmpcount from slzd_order_kd kd WHERE kd.did = ".$param['id']." and kd.del_user = 0 and kd.status IN (3,4)
                        union all
                        select count(*) as tmpcount from slzd_order_ky ky WHERE ky.did = ".$param['id']." and ky.del_user = 0 and ky.status IN (3,4)
                        union all
                        SELECT count(*) as tmpcount FROM  slzd_order_rrb as rrb  WHERE rrb.did = ".$param['id']." and rrb.del_user = 0 and rrb.orders_type =1 and rrb.status IN (3,4)
                        union all
                        SELECT count(*) as tmpcount FROM slzd_order_hy as hy WHERE hy.did = ".$param['id']." and hy.del_user = 0 and hy.status IN (3,4)
                    ) as a";
            $count =  $this->query($sql);
            $list['count'] = ceil(($count[0]['sum(tmpcount)'])/$orll_page);
            $list['page'] =  $page;
        }else{
            $sql = "SELECT kd.id id,kd.created_at created_at,kd.updated_at updated_at,kd.status status,time,time0,time2,time3,time5,begin,end,base_price,1 type,ex.name,ex.id ctype FROM slzd_order_kd as kd join slzd_app_express ex on kd.express_type = ex.id WHERE kd.did = ".$param['id']." and kd.del_user = 0 and kd.status = ".$param['status']."
                        union all SELECT id,created_at,updated_at,status,time,time0,time2,time3,time5,begin,end,base_price,4 as type,'顺风车' name,99 ctype FROM slzd_order_ky as  ky WHERE ky.did = ".$param['id']." and ky.del_user = 0 and ky.status = ".$param['status']."
                        union all SELECT rrb.id id,rrb.created_at created_at,rrb.updated_at updated_at,rrb.status status,time,time0,time2,time3,time5,begin,end,base_price,2 type,l.name name,l.id ctype FROM  slzd_order_rrb as rrb join slzd_rrb_list l on  rrb.type = l.id WHERE rrb.orders_type =1 and rrb.did = ".$param['id']." and rrb.del_user = 0 and rrb.status = ".$param['status']."
                        union all SELECT id,created_at, updated_at,status,time,time0,time2,time3,time5,begin,end,base_price,3 as type,'货急送' name, 0 ctype FROM slzd_order_hy as hy WHERE hy.did = ".$param['id']." and hy.del_user = 0 and hy.status = ".$param['status']." ORDER BY updated_at DESC LIMIT ".$limit.",".$orll_page;
            $list['row'] =  Db::query($sql);
            $sql = "select sum(tmpcount) from (
                        select count(*) as tmpcount from slzd_order_kd kd WHERE kd.did = ".$param['id']." and kd.del_user = 0 and kd.status = ".$param['status']."
                        union all
                        select count(*) as tmpcount from slzd_order_ky ky WHERE ky.did = ".$param['id']." and ky.del_user = 0 and ky.status = ".$param['status']."
                        union all
                        SELECT count(*) as tmpcount FROM  slzd_order_rrb as rrb  WHERE rrb.did = ".$param['id']." and rrb.del_user = 0 and rrb.status = ".$param['status']."
                        union all
                        SELECT count(*) as tmpcount FROM slzd_order_hy as hy WHERE hy.did = ".$param['id']." and hy.del_user = 0 and hy.status =".$param['status']."
                    ) as a";
            $count =  $this->query($sql);
            $list['count'] = ceil(($count[0]['sum(tmpcount)'])/$orll_page);
            $list['page'] =  $page;
        }
        foreach ($list['row'] as &$v){
            switch ($v['status']){
                case 0:
                    $v['statusName'] = '已取消';
                    break;
                case 2:
                    $v['statusName'] = '待支付';
                    break;
                case 3:
                    $v['statusName'] = '已支付';
                    break;
                case 4:
                    $v['statusName'] = '已确认';
                    break;
                case 5:
                    $v['statusName'] = '已完成';
                    break;
                case 6:
                    $v['statusName'] = '待支付';
                    break;
            }
        }
        return $list;
    }
    public function getUserAllData($page,$orll_page,$param){
        $limit = ($page-1)*$orll_page;
        if($param['status']==6){
            $sql = "SELECT kd.id id,kd.created_at created_at,kd.updated_at updated_at,kd.status status,time,time0,time2,time3,time5,begin,end,base_price,1 type,ex.name,ex.id ctype,'' cname FROM slzd_order_kd as kd join slzd_app_express ex on kd.express_type = ex.id WHERE kd.uid = ".$param['uid']." and kd.del_user = 0 and kd.status IN (0,1,2,3,4,5,6) 
                        union all 
                        SELECT id,created_at,updated_at,status,time,time0,time2,time3,time5,begin,end,base_price,4 as type,'顺风车' name,99 ctype, '' cname FROM slzd_order_ky as  ky WHERE ky.uid = ".$param['uid']." and ky.del_user = 0 and ky.status IN (0,1,2,3,4,5,6) 
                        union all 
                        SELECT bwz.id,bwz.created_at created_at,bwz.updated_at updated_at,bwz.status,time,time0,time2,time3,time5,111 begin,222 end,base_price,2 as type,'帮我赚' name,4 ctype,category_name cname FROM slzd_order_bwz as  bwz join slzd_rrb_getlist g on  bwz.type = g.id  WHERE bwz.uid = ".$param['uid']." and bwz.del_user = 0 and bwz.status IN(0,1,2,3,4,5,6)
                        union all 
                        SELECT rrb.id id,rrb.created_at created_at,rrb.updated_at updated_at,rrb.status status,time,time0,time2,time3,time5,begin,end,base_price,2 type,l.name name,l.id ctype,'' cname FROM  slzd_order_rrb as rrb join slzd_rrb_list l on  rrb.type = l.id WHERE rrb.uid = ".$param['uid']." and rrb.del_user = 0 and rrb.status IN (0,1,2,3,4,5,6) 
                        union all 
                        SELECT id,created_at,updated_at,status,time,time0,time2,time3,time5,begin,end,base_price,3 as type,'货急送' name, 0 ctype, '' caname FROM slzd_order_hy as hy WHERE hy.uid = ".$param['uid']." and hy.del_user = 0 and hy.status IN (0,1,2,3,4,5,6) ORDER BY updated_at DESC LIMIT ".$limit.",".$orll_page;
            $list['row'] =  Db::query($sql);
            $sql = "select sum(tmpcount) from (
                        select count(*) as tmpcount from slzd_order_kd kd WHERE kd.uid = ".$param['uid']." and kd.del_user = 0 and kd.status IN (0,1,2,3,4,5,6)
                        union all
                        select count(*) as tmpcount from slzd_order_ky ky WHERE ky.uid = ".$param['uid']." and ky.del_user = 0 and ky.status IN (0,1,2,3,4,5,6)
                        union all
                        SELECT count(*) as tmpcount FROM  slzd_order_rrb as rrb  WHERE rrb.uid = ".$param['uid']." and rrb.del_user = 0 and rrb.status IN (0,1,2,3,4,5,6)
                        union all
                        SELECT count(*) as tmpcount FROM slzd_order_hy as hy WHERE hy.uid = ".$param['uid']." and hy.del_user = 0 and hy.status IN (0,1,2,3,4,5,6)
                    ) as a";
            $count =  $this->query($sql);
            $list['count'] = ceil(($count[0]['sum(tmpcount)'])/$orll_page);
            $list['page'] =  $page;
        }elseif($param['status'] ==3) {
            $sql = "SELECT kd.id id,kd.created_at created_at,kd.updated_at updated_at,kd.status status,time,time0,time2,time3,time5,begin,end,base_price,1 type,ex.name,ex.id ctype,'' cname FROM slzd_order_kd as kd join slzd_app_express ex on kd.express_type = ex.id WHERE kd.uid = " . $param['uid'] . " and kd.del_user = 0 and kd.status IN (3,4) 
                        union all 
                        SELECT id,created_at,updated_at,status,time,time0,time2,time3,time5,begin,end,base_price,4 as type,'顺风车' name,99 ctype,'' cname FROM slzd_order_ky as  ky WHERE ky.uid = " . $param['uid'] . " and ky.del_user = 0 and ky.status IN (3,4) 
                        union all 
                        SELECT bwz.id,bwz.created_at created_at,bwz.updated_at updated_at,bwz.status,time,time0,time2,time3,time5,111 begin,222 end,base_price,2 as type,'帮我赚' name,4 ctype,category_name cname FROM slzd_order_bwz as  bwz join slzd_rrb_getlist g on  bwz.type = g.id WHERE bwz.uid = " . $param['uid'] . " and bwz.del_user = 0 and bwz.status IN(3,4)
                        union all 
                        SELECT rrb.id id,rrb.created_at created_at,rrb.updated_at updated_at,rrb.status status,time,time0,time2,time3,time5,begin,end,base_price,2 type,l.name name,l.id ctype,'' cname FROM  slzd_order_rrb as rrb join slzd_rrb_list l on  rrb.type = l.id WHERE rrb.uid = " . $param['uid'] . " and rrb.del_user = 0 and rrb.status IN (3,4) 
                        union all 
                        SELECT id,created_at,updated_at,status,time,time0,time2,time3,time5,begin,end,base_price,3 as type,'货急送' name, 0 ctype,'' cname FROM slzd_order_hy as hy WHERE hy.uid = " . $param['uid'] . " and hy.del_user = 0 and hy.status IN (3,4) ORDER BY updated_at DESC LIMIT " . $limit . "," . $orll_page;
            $list['row'] = Db::query($sql);
            $sql = "select sum(tmpcount) from (
                        select count(*) as tmpcount from slzd_order_kd kd WHERE kd.uid = " . $param['uid'] . " and kd.del_user = 0 and kd.status IN (3,4)
                        union all
                        select count(*) as tmpcount from slzd_order_ky ky WHERE ky.uid = " . $param['uid'] . " and ky.del_user = 0 and ky.status IN (3,4)
                        union all
                        SELECT count(*) as tmpcount FROM  slzd_order_rrb as rrb  WHERE rrb.uid = " . $param['uid'] . " and rrb.del_user = 0 and rrb.status IN (3,4)
                        union all
                        SELECT count(*) as tmpcount FROM slzd_order_hy as hy WHERE hy.uid = " . $param['uid'] . " and hy.del_user = 0 and hy.status IN (3,4)
                    ) as a";
            $count = $this->query($sql);
            $list['count'] = ceil(($count[0]['sum(tmpcount)']) / $orll_page);
            $list['page'] = $page;
        }elseif($param['status'] ==2) {
            $sql = "SELECT kd.id id,kd.created_at created_at,kd.updated_at updated_at,kd.status status,time,time0,time2,time3,time5,begin,end,base_price,1 type,ex.name,ex.id ctype,'' cname FROM slzd_order_kd as kd join slzd_app_express ex on kd.express_type = ex.id WHERE kd.uid = " . $param['uid'] . " and kd.del_user = 0 and kd.status IN (2,6) 
                        union all 
                        SELECT id,created_at,updated_at,status,time,time0,time2,time3,time5,begin,end,base_price,4 as type,'顺风车' name,99 ctype,'' cname FROM slzd_order_ky as  ky WHERE ky.uid = " . $param['uid'] . " and ky.del_user = 0 and ky.status IN (2,6) 
                        union all 
                        SELECT bwz.id,bwz.created_at created_at,bwz.updated_at updated_at,bwz.status,time,time0,time2,time3,time5,111 begin,222 end,base_price,2 as type,'帮我赚' name,4 ctype,category_name cname FROM slzd_order_bwz as  bwz join slzd_rrb_getlist g on  bwz.type = g.id WHERE bwz.uid = " . $param['uid'] . " and bwz.del_user = 0 and bwz.status IN(2,6)
                        union all 
                        SELECT rrb.id id,rrb.created_at created_at,rrb.updated_at updated_at,rrb.status status,time,time0,time2,time3,time5,begin,end,base_price,2 type,l.name name,l.id ctype,'' cname FROM  slzd_order_rrb as rrb join slzd_rrb_list l on  rrb.type = l.id WHERE rrb.uid = " . $param['uid'] . " and rrb.del_user = 0 and rrb.status IN (2,6) 
                        union all 
                        SELECT id,created_at,updated_at,status,time,time0,time2,time3,time5,begin,end,base_price,3 as type,'货急送' name, 0 ctype,'' cname FROM slzd_order_hy as hy WHERE hy.uid = " . $param['uid'] . " and hy.del_user = 0 and hy.status IN (2,6) ORDER BY updated_at DESC LIMIT " . $limit . "," . $orll_page;
            $list['row'] = Db::query($sql);
            $sql = "select sum(tmpcount) from (
                        select count(*) as tmpcount from slzd_order_kd kd WHERE kd.uid = " . $param['uid'] . " and kd.del_user = 0 and kd.status IN (2,6)
                        union all
                        select count(*) as tmpcount from slzd_order_ky ky WHERE ky.uid = " . $param['uid'] . " and ky.del_user = 0 and ky.status IN (2,6)
                        union all
                        SELECT count(*) as tmpcount FROM  slzd_order_rrb as rrb  WHERE rrb.uid = " . $param['uid'] . " and rrb.del_user = 0 and rrb.status IN (2,6)
                        union all
                        SELECT count(*) as tmpcount FROM slzd_order_hy as hy WHERE hy.uid = " . $param['uid'] . " and hy.del_user = 0 and hy.status IN (2,6)
                    ) as a";
            $count = $this->query($sql);
            $list['count'] = ceil(($count[0]['sum(tmpcount)']) / $orll_page);
            $list['page'] = $page;}
            else{
            $sql = "SELECT kd.id id,kd.created_at created_at,kd.updated_at updated_at,kd.status status,time,time0,time2,time3,time5,begin,end,base_price,1 type,ex.name,ex.id ctype FROM slzd_order_kd as kd join slzd_app_express ex on kd.express_type = ex.id WHERE kd.uid = ".$param['uid']." and kd.del_user = 0 and kd.status = ".$param['status']."
                        union all SELECT id,created_at,updated_at,status,time,time0,time2,time3,time5,begin,end,base_price,4 as type,'顺风车' name,99 ctype FROM slzd_order_ky as  ky WHERE ky.uid = ".$param['uid']." and ky.del_user = 0 and ky.status = ".$param['status']." 
                        union all SELECT bwz.id id,bwz.created_at,bwz.updated_at updated_at,bwz.status,time,time0,time2,time3,time5,'' begin,'' end,base_price,2 as type,'帮我赚' name,4 ctype FROM slzd_order_bwz as  bwz join slzd_rrb_getlist g on  bwz.type = g.id WHERE bwz.uid = ".$param['uid']." and bwz.del_user = 0 and bwz.status = ".$param['status']." 
                        union all SELECT rrb.id id,rrb.created_at created_at,rrb.updated_at updated_at,rrb.status status,time,time0,time2,time3,time5,begin,end,base_price,2 type,l.name name,l.id ctype FROM  slzd_order_rrb as rrb join slzd_rrb_list l on  rrb.type = l.id WHERE rrb.uid = ".$param['uid']." and rrb.del_user = 0 and rrb.status = ".$param['status']." 
                        union all SELECT id,created_at, updated_at,status,time,time0,time2,time3,time5,begin,end,base_price,3 as type,'货急送' name, 0 ctype FROM slzd_order_hy as hy WHERE hy.uid = ".$param['uid']." and hy.del_user = 0 and hy.status = ".$param['status']." ORDER BY updated_at DESC LIMIT ".$limit.",".$orll_page;
            $list['row'] =  Db::query($sql);
            $sql = "select sum(tmpcount) from (
                        select count(*) as tmpcount from slzd_order_kd kd WHERE kd.uid = ".$param['uid']." and kd.del_user = 0 and kd.status = ".$param['status']."
                        union all
                        select count(*) as tmpcount from slzd_order_ky ky WHERE ky.uid = ".$param['uid']." and ky.del_user = 0 and ky.status = ".$param['status']."
                        union all
                        SELECT count(*) as tmpcount FROM  slzd_order_rrb as rrb  WHERE rrb.uid = ".$param['uid']." and rrb.del_user = 0 and rrb.status = ".$param['status']."
                        union all
                        SELECT count(*) as tmpcount FROM slzd_order_hy as hy WHERE hy.uid = ".$param['uid']." and hy.del_user = 0 and hy.status =".$param['status']."
                    ) as a";
            $count =  $this->query($sql);
            $list['count'] = ceil(($count[0]['sum(tmpcount)'])/$orll_page);
            $list['page'] =  $page;
        }
        if($list['row']){
            foreach($list['row'] as &$v){
                $v['showtime'] = date('Y-m-d H:i:s',$v['time']);
            }
        }
        if(!$list){
            return '';
        }else{
            return $list;
            // return '';

        }
    }
    public function getUserGetOrderData($page,$orll_page,$param){
        $limit = ($page-1)*$orll_page;
        if($param['status']==6){
                        $sql = "SELECT kd.id id,kd.created_at created_at,kd.status status,time,time0,time2,time3,time5,begin,end,base_price,1 type,ex.name,ex.id ctype,'' cname FROM slzd_order_kd as kd join slzd_app_express ex on kd.express_type = ex.id WHERE kd.did = ".$param['id']." and kd.del_user = 0 and kd.status IN (0,1,2,3,4,5,6)
                        union all
                        SELECT id,created_at,status,time,time0,time2,time3,time5,begin,end,base_price,4 as type,'顺风车' name,99 ctype,'' cname FROM slzd_order_ky as  ky WHERE ky.did = ".$param['id']." and ky.del_user = 0 and ky.status IN (0,1,2,3,4,5,6)
                        union all
                        SELECT bwz.id,created_at,status,time,time0,time2,time3,time5,111 begin,222 end,base_price,2 as type,'帮我赚' name,4 ctype,category_name cname FROM slzd_order_bwz as  bwz WHERE bwz.did = ".$param['id']." and bwz.del_user = 0 and bwz.status IN(0,1,2,3,4,5,6)
                        union all
                        SELECT rrb.id id,rrb.created_at created_at,rrb.status status,time,time0,time2,time3,time5,begin,end,base_price,2 type,l.name name,l.id ctype,'' cname FROM  slzd_order_rrb as rrb join slzd_rrb_list l on  rrb.type = l.id WHERE rrb.did = ".$param['id']." and rrb.del_user = 0 and rrb.status IN (0,1,2,3,4,5,6)
                        union all
                        SELECT id,created_at,status,time,time0,time2,time3,time5,begin,end,base_price,3 as type,'货急送' name, 0 ctype,'' cname FROM slzd_order_hy as hy WHERE hy.did = ".$param['id']." and hy.del_user = 0 and hy.status IN (0,1,2,3,4,5,6) ORDER BY created_at DESC LIMIT ".$limit.",".$orll_page;
            $list['row'] =  Db::query($sql);
            $sql = "select sum(tmpcount) from (
                        select count(*) as tmpcount from slzd_order_kd kd WHERE kd.did = ".$param['id']." and kd.del_user = 0 and kd.status IN (0,2,3,4,5,6)
                        union all
                        select count(*) as tmpcount from slzd_order_ky ky WHERE ky.did = ".$param['id']." and ky.del_user = 0 and ky.status IN (0,2,3,4,5,6)
                        union all
                        SELECT count(*) as tmpcount FROM  slzd_order_rrb as rrb  WHERE rrb.did = ".$param['id']." and rrb.del_user = 0 and rrb.status IN (0,2,3,4,5,6)
                        union all
                        SELECT count(*) as tmpcount FROM slzd_order_hy as hy WHERE hy.did = ".$param['id']." and hy.del_user = 0 and hy.status IN (0,2,3,4,5,6)
                    ) as a";
            $count =  $this->query($sql);
            $list['count'] = ceil(($count[0]['sum(tmpcount)'])/$orll_page);
            $list['page'] =  $page;
        }elseif($param['status']==2){
            $sql = "SELECT kd.id id,kd.created_at created_at,kd.status status,time,time0,time2,time3,time5,begin,end,base_price,1 type,ex.name,ex.id ctype,'' cname FROM slzd_order_kd as kd join slzd_app_express ex on kd.express_type = ex.id WHERE kd.did = ".$param['id']." and kd.del_user = 0 and kd.status IN (2,6)
                        union all
                        SELECT id,created_at,status,time,time0,time2,time3,time5,begin,end,base_price,4 as type,'顺风车' name,99 ctype,'' cname FROM slzd_order_ky as  ky WHERE ky.did = ".$param['id']." and ky.del_user = 0 and ky.status IN (2,6)
                        union all
                        SELECT bwz.id,created_at,status,time,time0,time2,time3,time5,111 begin,222 end,base_price,2 as type,'帮我赚' name,4 ctype,category_name cname FROM slzd_order_bwz as  bwz WHERE bwz.did = ".$param['id']." and bwz.del_user = 0 and bwz.status IN(2,6)
                        union all
                        SELECT rrb.id id,rrb.created_at created_at,rrb.status status,time,time0,time2,time3,time5,begin,end,base_price,2 type,l.name name,l.id ctype,'' cname FROM  slzd_order_rrb as rrb join slzd_rrb_list l on  rrb.type = l.id WHERE rrb.did = ".$param['id']." and rrb.del_user = 0 and rrb.status IN (2,6)
                        union all
                        SELECT id,created_at,status,time,time0,time2,time3,time5,begin,end,base_price,3 as type,'货急送' name, 0 ctype,'' cname FROM slzd_order_hy as hy WHERE hy.did = ".$param['id']." and hy.del_user = 0 and hy.status IN (2,6) ORDER BY created_at DESC LIMIT ".$limit.",".$orll_page;
            $list['row'] =  Db::query($sql);
            $sql = "select sum(tmpcount) from (
                        select count(*) as tmpcount from slzd_order_kd kd WHERE kd.did = ".$param['id']." and kd.del_user = 0 and kd.status IN (2,6)
                        union all
                        select count(*) as tmpcount from slzd_order_ky ky WHERE ky.did = ".$param['id']." and ky.del_user = 0 and ky.status IN (2,6)
                        union all
                        SELECT count(*) as tmpcount FROM  slzd_order_rrb as rrb  WHERE rrb.did = ".$param['id']." and rrb.del_user = 0 and rrb.status IN (2,6)
                        union all
                        SELECT count(*) as tmpcount FROM slzd_order_hy as hy WHERE hy.did = ".$param['id']." and hy.del_user = 0 and hy.status IN (2,6)
                    ) as a";
            $count =  $this->query($sql);
            $list['count'] = ceil(($count[0]['sum(tmpcount)'])/$orll_page);
            $list['page'] =  $page;
        }elseif($param['status']==3){
            $sql = "SELECT kd.id id,kd.created_at created_at,kd.status status,time,time0,time2,time3,time5,begin,end,base_price,1 type,ex.name,ex.id ctype,'' cname FROM slzd_order_kd as kd join slzd_app_express ex on kd.express_type = ex.id WHERE kd.did = ".$param['id']." and kd.del_user = 0 and kd.status IN (3,4)
                        union all
                        SELECT id,created_at,status,time,time0,time2,time3,time5,begin,end,base_price,4 as type,'顺风车' name,99 ctype,'' cname FROM slzd_order_ky as  ky WHERE ky.did = ".$param['id']." and ky.del_user = 0 and ky.status IN (3,4)
                        union all
                        SELECT bwz.id,created_at,status,time,time0,time2,time3,time5,111 begin,222 end,base_price,2 as type,'帮我赚' name,4 ctype,category_name cname FROM slzd_order_bwz as  bwz WHERE bwz.did = ".$param['id']." and bwz.del_user = 0 and bwz.status IN(3,4)
                        union all
                        SELECT rrb.id id,rrb.created_at created_at,rrb.status status,time,time0,time2,time3,time5,begin,end,base_price,2 type,l.name name,l.id ctype,'' cname FROM  slzd_order_rrb as rrb join slzd_rrb_list l on  rrb.type = l.id WHERE rrb.did = ".$param['id']." and rrb.del_user = 0 and rrb.status IN (3,4)
                        union all
                        SELECT id,created_at,status,time,time0,time2,time3,time5,begin,end,base_price,3 as type,'货急送' name, 0 ctype,'' cname FROM slzd_order_hy as hy WHERE hy.did = ".$param['id']." and hy.del_user = 0 and hy.status IN (3,4) ORDER BY created_at DESC LIMIT ".$limit.",".$orll_page;
            $list['row'] =  Db::query($sql);
            $sql = "select sum(tmpcount) from (
                        select count(*) as tmpcount from slzd_order_kd kd WHERE kd.did = ".$param['id']." and kd.del_user = 0 and kd.status IN (3,4)
                        union all
                        select count(*) as tmpcount from slzd_order_ky ky WHERE ky.did = ".$param['id']." and ky.del_user = 0 and ky.status IN (3,4)
                        union all
                        SELECT count(*) as tmpcount FROM  slzd_order_rrb as rrb  WHERE rrb.did = ".$param['id']." and rrb.del_user = 0 and rrb.status IN (3,4)
                        union all
                        SELECT count(*) as tmpcount FROM slzd_order_hy as hy WHERE hy.did = ".$param['id']." and hy.del_user = 0 and hy.status IN (3,4)
                    ) as a";
            $count =  $this->query($sql);
            $list['count'] = ceil(($count[0]['sum(tmpcount)'])/$orll_page);
            $list['page'] =  $page;
        }else{
                        $sql = "SELECT kd.id id,kd.created_at created_at,kd.status status,time,time0,time2,time3,time5,begin,end,base_price,1 type,ex.name,ex.id ctype,'' cname FROM slzd_order_kd as kd join slzd_app_express ex on kd.express_type = ex.id WHERE kd.did = ".$param['id']." and kd.del_user = 0 and kd.status = ".$param['status']."
                        union all SELECT id,created_at,status,time,time0,time2,time3,time5,begin,end,base_price,4 as type,'顺风车' name,99 ctype,'' cname FROM slzd_order_ky as  ky WHERE ky.did = ".$param['id']." and ky.del_user = 0 and ky.status = ".$param['status']."
                        union all SELECT bwz.id,bwz.created_at,bwz.status,time,time0,time2,time3,time5,'' begin,'' end,base_price,2 as type,'帮我赚' name,4 ctype,category_name cname FROM slzd_order_bwz as  bwz join slzd_rrb_getlist g on  bwz.type = g.id WHERE bwz.did = ".$param['id']." and bwz.del_user = 0 and bwz.status = ".$param['status']."
                        union all SELECT rrb.id id,rrb.created_at created_at,rrb.status status,time,time0,time2,time3,time5,begin,end,base_price,2 type,l.name name,l.id ctype,'' cname FROM  slzd_order_rrb as rrb join slzd_rrb_list l on  rrb.type = l.id WHERE rrb.did = ".$param['id']." and rrb.del_user = 0 and rrb.status = ".$param['status']."
                        union all SELECT id,created_at,status,time,time0,time2,time3,time5,begin,end,base_price,3 as type,'货急送' name, 0 ctype,'' cname FROM slzd_order_hy as hy WHERE hy.did = ".$param['id']." and hy.del_user = 0 and hy.status = ".$param['status']." ORDER BY created_at DESC LIMIT ".$limit.",".$orll_page;
            $list['row'] =  Db::query($sql);
            $sql = "select sum(tmpcount) from (
                        select count(*) as tmpcount from slzd_order_kd kd WHERE kd.did = ".$param['id']." and kd.del_user = 0 and kd.status = ".$param['status']."
                        union all
                        select count(*) as tmpcount from slzd_order_ky ky WHERE ky.did = ".$param['id']." and ky.del_user = 0 and ky.status = ".$param['status']."
                        union all
                        SELECT count(*) as tmpcount FROM  slzd_order_rrb as rrb  WHERE rrb.did = ".$param['id']." and rrb.del_user = 0 and rrb.status = ".$param['status']."
                        union all
                        SELECT count(*) as tmpcount FROM slzd_order_hy as hy WHERE hy.did = ".$param['id']." and hy.del_user = 0 and hy.status =".$param['status']."
                    ) as a";
            $count =  $this->query($sql);
            $list['count'] = ceil(($count[0]['sum(tmpcount)'])/$orll_page);
            $list['page'] =  $page;
        }
        foreach($list['row'] as &$v){
            $v['showtime'] = date('Y-m-d H:i:s',$v['time']);
        }
        return $list;
    }
}